<admintpl file="header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<form class="form-horizontal js-ajax-form" action="{:U('AdminGoodsProperty/editPropertyPost')}" method="post">
		<input type="hidden" name="post[cat_id]" value="{$cat_id}" />
		<input type="hidden" name="post[category_name]" value="{$category}" />
		<input type="hidden" name="post[paramname]" value="{$paramname}" />
			<div class="tabbable">
		        <div class="tab-content">
		          <div class="tab-pane active" id="A">
						<fieldset>
							<div class="control-group">
								<label class="control-label">{:L('EMALL_ADMINGOODS_PROPERTY_NAME')}</label>
								<div class="controls">
									<input type="text" name="post[pname]" value="{$pname}" readonly="true">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">{:L('PROPERTY_CATEGORY_NAME')}</label>
								<div class="controls">
								<select name="property[category_name]" id="category_name">
								</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">{:L('EMALL_ADMINGOODS_PARAM_NAME')}</label>
								<div class="controls">
									<input type="text" name="property[paramname]" id="paramname" value={$paramname}><span class="form-required">*</span>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">{:L('EMALL_ADMINGOODS_FORMTYPE')}</label>
								<div class="controls">
								<select name="property[formtype]" id="formtype">
  									<option value="1">文本框</option>
  									<option value="2">下拉列表框</option>
  									<option value="3">单选框</option>
								</select>
								</div>
								<div id="selectParam" style="display:none;">
								<label class="control-label">{:L('EMALL_ADMINGOODS_PARAMLIST')}</label>
								<div class="controls">
									<textarea name="property[selectParam]" rows="5" cols="57" placeholder="列表项之间请用回车分隔">{$data.selectParam}</textarea>*
								</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">{:L('EMALL_ADMINGOODS_DESCRIPTION')}</label>
								<div class="controls">
									<textarea name="property[description]" id="description" rows="5" cols="57">{$data.description}</textarea>
								</div>
							</div>

						</fieldset>
		          </div>

		        </div>
		    </div>
		    <div class="form-actions">
		     	<button class="btn btn-primary" id="submitBtn">{:L('SAVE')}</button>
		      	<a class="btn" href="{:U('AdminGoodsProperty/listProperty',array('id'=>$cat_id,'pname'=>$pname))}">{:L('BACK')}</a>
		    </div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
	var propertyData=$.parseJSON('{$propertyData}');
	var category_name='{$category}';
	var paramname='{$paramname}';

    	$(function(){
    		//表单赋值
    		var categroyOption='';
    		$.each(propertyData,function(index,Item){
    			var selected='';
    			if(index==category_name){
					selected='selected';
					$.each(Item,function(pidx,Param){
						if(paramname==Param.paramname){
							$('#formtype').val(Param.formtype);
							$('#description').val(Param.description);
							if(parseInt(Param.formtype)==2){
								var selectParam='';
								$.each(Param.selectParam,function(sidx,option){
									selectParam+=selectParam==''?option:"\n"+option;
								})
								$('#selectParam textarea').val(selectParam);
								$('#selectParam').show();
							}
							return false;
						}
					})
    			}
    			categroyOption+='<option value="'+index+'" '+selected+'>'+index+'</option>'
    		})
    		$('#category_name').append(categroyOption);

 			$selectParam=$('#selectParam');
 			if($selectParam.find('textarea').val()!=''){
 				$selectParam.css({'display':'block'});
 			}

    		$("#formtype").change(function(){
    			//alert("baby");
    			exploreView(parseInt($(this).val()));
    		});

    		function exploreView($type){
    			$eviewlabel=$("#exploreView label");
    			$eviewForm=$("#exploreView .controls");
    			//alert($type);
    			switch($type){
    				case(1):
    				$selectParam.css({'display':'none'});
    				$eviewlabel.text($("#paramname").val())
    				$eviewForm.html("<input type=\"text\" value=\"\">")
    				break;  
    				case(2):
    				$selectParam.css({'display':'block'});
    				$eviewlabel.text($("#paramname").val())
    				$eviewForm.html("<select></select>")
    				break; 
    				case(3):
    				$selectParam.css({'display':'none'});
    				$eviewlabel.text($("#paramname").val())
    				$eviewForm.html("<select></select>")
    				break; 
    				case(4):
    				$selectParam.css({'display':'none'});
    				$eviewlabel.text($("#paramname").val())
    				$eviewForm.html("<select></select>")
    				break;    
    				default:	

    			}
			
    		}

			$('#submitBtn').click(function(event){
				$this=$(this);
				$this.attr('disabled',true);
				if($('#selectParam textarea').val()=='' && $('#formtype').val()=='2'){
					alert('列表项值不能为空！');
					return false;
				}else if($('#paramname').val()==''){
					alert('属性参数名不能为空！');
					return false;			
				}
				$.post("{:U('AdminGoodsProperty/editPropertyPost')}",$("form").serialize(),function(data){
					if(data.status==1){
						$this.removeAttr('disabled');
						alert('编辑保存成功!');
						//window.location.reload();
						location.href=data.data.returnURL;
					}else{
						alert('编辑保存失败!');
					}
					//console.log(data.data.returnURL);
				});
			})

    	});
    </script>

</body>
</html>